﻿@model IEnumerable<TextManager.Models.Task>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>
<div style="text-align:center">
    <form method="get" class="form-inline text-center" style="margin:10px">
        所属用户：@Html.DropDownList("id", null, new { @class = "form-control" })
        任务内容：<input type="text" name="Content" class="form-control" placeholder="请输入内容关键字" />
        <input type="submit" value="查询" class="btn btn-primary" />
        @Html.ActionLink("添加", "Create", null, new { @class = "btn btn-primary" })
    </form>
</div>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.TaskPriority)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Content)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.AddTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.TaskState)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.FinishedTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Project.ProjectName)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @*任务优先级*@
                @if (item.TaskPriority == 1)
                {
                    @:高
                }
                else if (item.TaskPriority == 2)
                {
                    @:中
                }
                else if (item.TaskPriority == 3)
                {
                    @:低
                }

            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Content)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.AddTime)
            </td>
            <td>
                @(item.TaskState==1?"未完成":"已完成")
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.FinishedTime)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Project.ProjectName)
            </td>
            <td>
                @Html.ActionLink("修改", "Edit", new { id = item.TaskID }) |
                @Html.ActionLink("详情", "Details", new { id = item.TaskID }) |
                @*@Html.ActionLink("删除", "Delete", new { id=item.TaskID })*@
                <a href="#" data-del="@item.TaskID">删除</a>
            </td>
        </tr>
    }

</table>

@section scripts{
    <script type="text/javascript">
        $(function () {
            $("a[data-del]").click(function () {
                var $this = $(this);
                var id = $this.attr("data-del");
                if (!confirm("您确定要删除id=" + id + "?")) return;
                $.post("@Url.Content("~/Task/Delete")", { id: id }, function (res) {
                    if (res == true) {
                        alert("删除成功！");
                        location.reload();
                    }
                })
            })
        })
    </script>

}
